package com.xingda.packing.dmss.config.appset;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 读取配置的参数和系数
 */
@Slf4j
public class AppSetParam extends JSONObject implements IAppSet {

    private static final long serialVersionUID = 1L;

    /**
     * 可放轮概率 扭转值、方差算出的可以放轮的概率，大于等于这个系数则可以放轮
     */
    public static double success_factor = 0.78;

    /**
     * 缓存位获得可放轮有时间优先和概率大优先，从倒数第几个开始概率优先
     */
    public static int probability_priority_last_num = 4;

    /**
     * 每层工字轮信息是否上传
     */
    public static boolean is_floor_upload = false;
    /**
     * 展示重卷轮剩余个数的LED灯是否展示
     */
    public static boolean led_anew_open = false;

    /**
     * 页面展示轮子的顺序
     */
    public static List<Integer> wheel_sort_index = Arrays.asList(9, 6, 3, 0, 1, 4, 7, 10, 11, 8, 5, 2);

    /**
     * 报警消息是否向信息中心发送
     */
    public static boolean is_alarm_send = false;

    /**
     * 自动删除n分钟前的卸轮记录
     */
    public static int delete_down_wheel_minute_ago = 480;

    /**
     * 机器人(5分钟)未动报警时间
     */
    public static int robot_not_move_alarm_minute = 5;

    /**
     * 是否自动删除已经判断为装箱的卸轮记录
     */
    public static boolean auto_reomve_packing_downwheel = false;
    public static int cache_size = 8;

    @Override
    public void init() {

        log.info("------------------加载AppSetParam配置------------------");

        Double success_factor_init = this.getDouble("success_factor");
        if (Objects.nonNull(success_factor_init)) {
            success_factor = success_factor_init;
        }
        log.info("可放轮概率：{}", success_factor);

        Integer probability_priority_last_num_init = this.getInteger("probability_priority_last_num");
        if (Objects.nonNull(probability_priority_last_num_init)) {
            probability_priority_last_num = probability_priority_last_num_init;
        }
        log.info("概率优先从倒数第几个开始：{}", probability_priority_last_num);

        Boolean is_floor_upload_init = this.getBoolean("is_floor_upload");
        if (Objects.nonNull(is_floor_upload_init)) {
            is_floor_upload = is_floor_upload_init;
        }
        log.info("每层工字轮信息是否上传：{}", is_floor_upload);

        Boolean led_anew_open_init = this.getBoolean("led_anew_open");
        if (Objects.nonNull(led_anew_open_init)) {
            led_anew_open = led_anew_open_init;
        }
        log.info("展示重卷轮剩余个数的LED灯是否展示：{}", led_anew_open);

        List<Integer> wheel_sort_index_init = this.getJSONArray("wheel_sort_index").toJavaList(Integer.class);
        if (Objects.nonNull(wheel_sort_index_init)) {
            wheel_sort_index = wheel_sort_index_init;
        }
        log.info("页面展示轮子的顺序：{}", wheel_sort_index);

        Boolean is_alarm_send_init = this.getBoolean("is_alarm_send");
        if (Objects.nonNull(is_alarm_send_init)) {
            is_alarm_send = is_alarm_send_init;
        }
        log.info("报警消息是否向信息中心发送：{}", is_alarm_send);

        Integer delete_down_wheel_minute_ago_init = this.getInteger("delete_down_wheel_minute_ago");
        if (Objects.nonNull(delete_down_wheel_minute_ago_init)) {
            delete_down_wheel_minute_ago = delete_down_wheel_minute_ago_init;
        }
        log.info("自动删除{}分钟前的卸轮记录", delete_down_wheel_minute_ago);

        Integer robot_not_move_alarm_minute_init = this.getInteger("robot_not_move_alarm_minute");
        if (Objects.nonNull(robot_not_move_alarm_minute_init)) {
            robot_not_move_alarm_minute = robot_not_move_alarm_minute_init;
        }
        log.info("机器人{}分钟未动报警时间", robot_not_move_alarm_minute);

        Boolean auto_reomve_packing_downwheel_init = this.getBoolean("auto_reomve_packing_downwheel");
        if (Objects.nonNull(auto_reomve_packing_downwheel_init)) {
            auto_reomve_packing_downwheel = auto_reomve_packing_downwheel_init;
        }
        log.info("是否自动删除已经判断为装箱的卸轮记录：{}", auto_reomve_packing_downwheel);
        Integer cache_size_init = this.getInteger("cache_size");
        if (Objects.nonNull(cache_size_init)) {
            cache_size = cache_size_init;
        }
        log.info("缓存位报警阈值:{}", cache_size);
    }
}
